//
//  JJBaseViewController.swift
//  JJSina
//
//  Created by mac on 2017/12/4.
//  Copyright © 2017年 xinyuan. All rights reserved.
//

import UIKit

class JJBaseViewController: UIViewController {

    // 判断用户是否登录
    let isLogin: Bool = JJOAuthViewModel.shared.isLogin
    // 定义一个访客视图
    var baseView: JJBaseView?
    
    lazy var tableView: UITableView = UITableView()
    override func loadView() {
        if isLogin {
            // 登录
            view = tableView
            
        } else {
            // 未登录
            setupBaseView()
        }
    }
    private func setupBaseView() {
        baseView = JJBaseView()
        view = baseView
        // 未登录状态才设置按钮
        setupNavigationItem()
        baseView?.clouser = {
            self.loginOrRegisterClick()
        }
    }
    //MARK: - 设置导航按钮
    private func setupNavigationItem() {
        // 左侧
        navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: nil, title: "登录", target: self, action: #selector(loginOrRegisterClick))
        // 右侧
        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: nil, title: "注册", target: self, action: #selector(loginOrRegisterClick))
    }
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    //MARK: - 监听的方法
    @objc private func loginOrRegisterClick() {
//        print("点击登录或注册按钮")
        let oauthVC = JJOAuthViewController()
       self.present(JJMainNavigationController(rootViewController:oauthVC), animated: true, completion: nil)
        
    }

}

